<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>索引页</title>
    <script src="${pageContext.request.contextPath}/js/jquery-3.4.1.min.js"></script>
</head>
<body>

<div>
    <p><input type="text" id="username" placeholder="账户"></p>
    <p><input type="text" id="password" placeholder="密码"></p>
</div>
<p><button id="btn2">登录</button></p>
<p><button id="btn1">发送ajax请求1</button></p>

<p>dev2增加的p标签</p>

<a href="${pageContext.request.contextPath}/html/index.html">点击跳转</a>

</body>

<script type="text/javascript">
    let btn2 = document.querySelector("#btn2");
    btn2.addEventListener('click', e=>{
        let data = {
            username:document.getElementById("username").value,
            password:document.getElementById("password").value
        }
        console.log(data)
        data = JSON.stringify(data)
        console.log(data)
        fetch('/user/login.do',{
        'method':'post',
            'mode':'cors',
            "Access-Control-Allow-Origin" : "*",
            "Access-Control-Allow-Credentials" : true,
            'headers':{
            'content-type':'application/json'
        },
        'body':data
    }).then(
        rs => {
        console.log(rs)
    })
    })
</script>

<%--<script>--%>

    <%--let btn1 = document.querySelector("#btn1");--%>
    <%--btn1.onclick = function () {--%>
        <%--console.log("btn1......");--%>
    <%--}--%>
    <%--$("#btn2").click(function () {--%>
        <%--$.ajax({--%>
            <%--url:"${pageContext.request.contextPath}/user/login.do",--%>
            <%--// contentType:"",--%>
            <%--data:{--%>
                <%--username:document.getElementById("username").value,--%>
                <%--password:document.getElementById("password").value--%>
            <%--},--%>
            <%--dataType:"json",--%>
            <%--type:"post",--%>
            <%--success:function (data) {--%>
                <%--let json = JSON.stringify(data);--%>
                <%--console.log(json);--%>
            <%--},--%>
            <%--error:function (error) {--%>
                <%--console.log(error);--%>
            <%--}--%>
        <%--})--%>
    <%--})--%>

<%--</script>--%>

</html>
